/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
*/
var twoSum = function(nums, target) {
  let i = 0, j = nums.length - 1;
  while(i <= j) {
    if(nums[i] + nums[j] == target) {
      return [nums[i], nums[j]];
    } else if (nums[i] + nums[j] > target) {
      j--;
    } else {
      i++;
    }
  }
  return [];
};
let nums = [2,7,11,15], target = 9;
console.log(twoSum(nums, target));
nums = [10,26,30,31,47,60], target = 40;
console.log(twoSum(nums, target));
